<?php 
class ColumnsController extends CommonController{

	private $model;

	public function __init(){
		parent::__init();
		$this->model = K('Columns');
	}
	public function index(){
		$allData = $this->model->get_data();
		//树状数据
		$allData= Data::tree($allData,'title','cnid','pid');
		$this->assign('allData',$allData);

	$this->display();
	}

	public function add(){

		if(IS_POST){
			if($this->model->create()){
			$this->model->add_data();
			$this->success('添加成功',U('index'));
			}
			$this->error($this->model->error);
		}
		$this->display();
	}


	public function add_son(){
		if(IS_POST){
			if($this->model->create()){
				$this->model->add_data();
				$this->success('添加成功',U('index'));
			}
			$this->error($this->model->error);
		}

		$one_data = $this->model->find_data(array('cnid'=>Q('get.cnid', 0, 'intval')));

		$this->assign('one_data',$one_data);
		$this->display();
	}


	public function del(){

		if($this->model->del_data(Q('get.cnid',0,'intval'))){
			$this->success('删除成功');
		}else{
		$this->error($this->model->error);
		}
	}

	public function ajax_show(){
 		if(IS_AJAX){
 			$this->model->ajax_change_stat();
 			$arr = array(
			'status' => 1,
			'message'=>'修改成功',
			);
			$this->ajax($arr);
 		}
 	}

 	public function edit_cate(){
 		if (IS_POST) {
 			$this->model->update_data(array('cnid'=>Q('get.cnid',0,'intval')));
 			$this->success('修改成功',U('Index'));
 		}

 	$default = $this->model->find_data(Q('get.cnid'),0,'intval');
 	$this->assign('default',$default);



 	// 获得所有的分类
 	$cateData = $this->model->get_data();
 	$this->assign('cateData',$cateData);
 	$this->display();
 	}

}




 ?>